#include "faceaction.h"
#include <QVideoFrame>
FaceAction::FaceAction(QObject *parent) :
    QThread(parent)
{
    mType=ACTION_IDLE;
    mDetector=new FaceDetector;

    Init();
    start();
}


bool FaceAction::Init()
{
    mDetector->Init();
}

void FaceAction::run()
{
    while(1)
    {
        mLock.lock();
        switch(mType)
        {
            case ACTION_DETECT:
            {
                doDetect();
                break;
            }
            case ACTION_EXTRACT:
            {
                doExtract();
                break;
            }
            case ACTION_SCAN:
            {
                doCompare();
                break;
            }
            case ACTION_IDLE:
            {
                mWait.wait(&mLock);
                break;
            }
        }
        mLock.unlock();
    }
}

void FaceAction::doDetect()
{

    QVideoFrame currentFrame;
    if(mCameraBuf->top(currentFrame)==false)
        return;
    QImage image(currentFrame.bits(),currentFrame.width(), currentFrame.height(),currentFrame.bytesPerLine(),QImage::Format_RGB888);
    mCameraBuf->Pop();

    QVector<QRect> faces=mDetector->DoDetect(image);

    emit FaceDetected(faces);

}
void doExtract()
{

}

void doCompare()
{

}
